import { createActions } from 'redux-actions'

const init = (config) => {
  const actionCreators = createActions({
    'saveMallInfo': data => ({
      diamonds: data.data
    }) // payload creator,
  })
  const mall = {
    loadItem(dispatch, getState) {
       // 参数说明：goods_type ：1代表钻石，2代表群卡
      const url = `${config.pre}/Order/shopping/${Cookies.get('areaCode')}/1`
      const opt = { method: 'GET' }
      fetchJson(url, opt).then(data => {
        console.log('data', data);
        if (data.result) {
          console.log('登录过期!')
          if (data.result == 600) {
            sessionStorage.setItem('result600', 'true')
            window.location.href = data.data //
          }
          return
        }
        dispatch(actionCreators.saveMallInfo(data))
      })
    }
  }
  return mall
}

export default init